﻿using ControlzEx.Standard;
using DataChangeTools.Module.Core;
using DataChangeTools.Utils;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DataChangeTools.SplashModule.ViewModels
{
    public class SplashViewViewModel : BindableBase
    {
        private readonly IEventAggregator _eventAggregator;
        #region 字段
        private string versionStr;

        public string VersionStr
        {
            get { return versionStr; }
            set => SetProperty(ref versionStr, value); // 自动触发属性变更通知
        }


        private string loadStateStr;

        public string LoadStateStr
        {
            get { return loadStateStr; }
            set => SetProperty(ref loadStateStr, value); // 自动触发属性变更通知
        }
        #endregion


        public SplashViewViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;
            InitData();
        }

        public void InitData()
        {

            Assembly assembly = Assembly.GetEntryAssembly();
            Version version = assembly.GetName().Version;
            //string version1 = Assembly.GetAssembly(typeof(DataChangeTools)).GetName().Version.ToString();
            versionStr = $"版本：{version}";

            //versionStr = $"版本：{ConfigHelper.GetValue("Version")}";


            loadStateStr = "初始化...";
            _eventAggregator.GetEvent<MessageUpdateEvent>().Subscribe(e => UpdateMessage(e.Message));
        }

        private void UpdateMessage(string message)
        {
            var ChineseMessage = "";
            if (string.IsNullOrEmpty(message))
            {
                return;
            }
            switch (message)
            {
                case "AutoUpdaterModule":
                    ChineseMessage = "自动更新模块加载...";
                    break;
                default:
                    ChineseMessage = "初始化...";
                    break;
            }
            //转换
            LoadStateStr = string.Concat(Environment.NewLine, ChineseMessage, "...");
            System.Threading.Thread.Sleep(1000);
        }

    }
}
